package bjtu.pinet.service;


import bjtu.pinet.common.ParsingResult;
import bjtu.pinet.common.PinetEtherType;
import bjtu.pinet.dto.DecisionResultObject;
import bjtu.pinet.dto.PinetNetworkConfigObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * author:chushuai
 * date:2021.2.13
 */
public class ModeDecisionServiceLocalImpl implements ModeDecisionService {
    private final Logger log = LoggerFactory.getLogger(getClass());
    private boolean isTurn;
    private boolean isSupport;
    private String ndnName;
    private IPToNDNTurnService ipToNDNTurnService = new IPToNDNTurnServiceLocalImpl();

    @Override
    public DecisionResultObject modeDecision(ParsingResult parsingResult) {
        DecisionResultObject decisionResultObject =
                new DecisionResultObject(false, false,
                        parsingResult.getPrincipalsObject(),
                        parsingResult.getNetworkTypeId(),
                        parsingResult.getEtherType(),
                        parsingResult.getPacketParsingResult(),
                        parsingResult.getPrincipalsObject(),
                        parsingResult.getReceiceFrom().toString());
        if (true) {
            isSupport = true;
            if (parsingResult.getNetworkTypeId() == PinetEtherType.IPV4.getNetworkTypeId()) {
                ndnName = ipToNDNTurnService.getNDNName(parsingResult);
                log.info("---------------------ndnname是------------------" + ndnName);
                isTurn = ipToNDNTurnService.ipToNDN(ndnName);
                if (isTurn) {
                    decisionResultObject.setTurn(isTurn);
                    ParsingResult.PrincipalsObject principalsObject = new ParsingResult.PrincipalsObject(ndnName, ndnName);
                    decisionResultObject.setDecisionPrincipalsObject(principalsObject);
                }
            } else {
                isTurn = false;
            }
        } else {
            isSupport = false;
        }
        decisionResultObject.setSupport(isSupport);
        return decisionResultObject;
    }
}
